#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
typedef struct SListNode
{
    int val;
    struct SListNode* next;
}SLTNode;
void SLPushFront(SLTNode** pphead, int n)
{
    int i = n;
    while (n--)
    {
        SLTNode* newnode = malloc(sizeof(SLTNode));
        newnode->next = *pphead;
        newnode->val = i;
        --i;
        *pphead = newnode;
    }
}
void Circu(SLTNode* phead)
{
    SLTNode* ptail = phead;
    while (ptail->next)
    {
        ptail = ptail->next;
    }
    ptail->next = phead;
}
SLTNode* Del(SLTNode* phead, int n, int m)
{
    SLTNode* pcur = phead;
    SLTNode* prev;
    for (int i = 0; i < n - 1; ++i)
    {
        for (int numoff = 1; numoff < m; ++numoff)
        {
            prev = pcur;
            pcur = pcur->next;
            if (numoff == m - 1)
            {
                pcur = pcur->next;
                prev->next = pcur;
            }
        }
    }
    return pcur;
}
int ysf(int n, int m) {
    // write code here
    SLTNode* Slist = NULL;
    SLPushFront(&Slist, n);
    Circu(Slist);

    return Del(Slist, n, m)->val;
}